#pragma once

#include "CScriptCore.hpp"

namespace CScript
{
	template <typename DestT>
	struct tCast
	{
		template <typename SrcT> //Default cast
		static DestT Cast(const SrcT& Src) {return DestT(Src);}

		template <> //To DestT from string
		static DestT Cast(const std::string& Src)
		{
			DestT Ret;
			std::istringstream(Src) >> Ret;
			return Ret;
		}
	};

	template <>
	struct tCast<int64>
	{
		template <typename SrcT>
		static int64 Cast(const SrcT& Src)
		{
			return (int64) Src;
		}

		template <>
		static int64 Cast(const std::string& Src)
		{
			return StrToInt64(Src.c_str());
		}
	};

	template <>
	struct tCast<std::string>
	{
		template <typename SrcT> static std::string Cast(const SrcT& Src)
		{
			std::stringstream oss;
			oss << Src;
			return oss.str();
		}

		template <> static std::string Cast(const std::string& Src) {return Src;}
		template <> static std::string Cast(const int64& Src) {return Int64ToStr(Src);}
	};

	template <typename DestType> struct value_cast
	{
		template <typename SrcType> static DestType cast(const SrcType& Src) {return tCast<DestType>::Cast(Src);}
	};
}
